This section describes the resource you use to define your component. If you are developing a component, you should be familiar with the format and content of a component resource.
A component resource (a resource of type 'thng' ) stores all of the information about a component in a single file. The component resource contains all the information needed to register a code resource as a component. Information in the component resource tells the Component Manager where to find the code for the component.
If you are developing an application that uses components, you do not need to know about component resources.
If you are developing a component or an application that registers components, you should be familiar with component resources. The Component Manager automatically registers any components that are stored in component files in the Extensions folder. The file type for component files must be set to 'thng' . If you store your component in a component file in the Extensions folder, you do not need to create an application to register the component.
The Component Manager provides routines that register components. The RegisterComponent function registers components that are not stored in resource files. The RegisterComponentResource and RegisterComponentResourceFile functions register components that are stored as component resources in a component file. If you are developing an application that registers components, you should use the routine that is appropriate to the storage format of the component. For more information about how your application can register components, see "Registering Components," .
This section describes the component resource, which must be provided by all components stored in a component file. Applications that register a component using the RegisterComponent function must also provide the same information as that contained in a component resource.
For compatibility with early versions of the Component Manager, a component resource must be locked.
The ComponentResource data type defines the structure of a component resource. (You can also optionally append to the end of this structure the information defined by the ComponentResourceExtension data type, as shown in Figure 5 .)
ComponentResource =
RECORD
cd: {registration information}
ComponentDescription;
component: ResourceSpec; {code resource}
componentName: ResourceSpec; {name string resource}
componentInfo: ResourceSpec; {info string resource}
componentIcon: ResourceSpec; {icon resource}
END;
A resource specification record, defined by the data type ResourceSpec , describes the resource type and resource ID of the component's code, name, information string, or icon. The resources specified by the resource specification records must reside in the same resource file as the component resource itself.
ResourceSpec =
RECORD
resType: OSType; {resource type}
resId: Integer; {resource ID}
END;
You can optionally include in your component resource the information defined by the ComponentResourceExtension data type:
ComponentResourceExtension =
RECORD
componentVersion: LongInt; {version of component}
componentRegisterFlags: LongInt; {additional flags}
componentIconFamily: Integer; {resource ID of icon }
{ family}
END;
CONST
componentDoAutoVersion = 1;
componentWantsUnregister = 2;
componentAutoVersionIncludeFlags = 4;
You store a component resource, along with other resources for the component, in the resource fork of a component file. Figure 4 shows the structure of a component file.
Figure 4 Format of a component file
You can also store other resources for your component in your component file. For example, you should include 'FREF' , 'BNDL' , and icon family resources so that the Finder can associate the icon identifying your component with your component file. When designing the icon for your component file, you should follow the same guidelines as those for system extension icons. See Macintosh Human Interface Guidelines for information on designing an icon. See the chapter "Finder Interface" in Inside Macintosh: Macintosh Toolbox Essentials for information on the 'FREF' and 'BNDL' resources.
Figure 5 shows the structure of a component resource.
Figure 5 Structure of a compiled component ( 'thng' ) resource